#!/usr/bin/env python
# -*- coding: utf-8 -*-
from settings import ENVIROMENT
# from utility.pgsql_manager import PgSqlManager
if ENVIROMENT == 'PRODUCT':
    from gevent import monkey
    from gevent.pywsgi import WSGIServer
    monkey.patch_all()

from flask import Flask
from flask_restful import Api
from flask_cors import CORS
import urls
app = Flask(__name__)
@app.after_request
def response_catch (res):
    return res
app.config.from_pyfile('settings.py', silent=True)
api = Api(app)
urls.add_routers(api)
CORS(app, supports_credentials=True)

# db.set_instance()
# with app.app_context():
    # pgDB = PgSqlManager().get_instance()
    # pgDB.init_app(app)
if __name__ == '__main__':
    if ENVIROMENT == 'PRODUCT':
        # 生产环境
        http_server = WSGIServer(('0.0.0.0', 5000), app)
        http_server.serve_forever()
    else:
        # 开发环境
        app.run(host='0.0.0.0', port=5000, debug=True)
